|
1
|
|
|
|
|
2
|
|
|
var |
|
3
|
|
|
window = require('window'), |
|
4
|
|
|
ko = window.ko, |
|
5
|
|
|
_ = require('_'), |
|
6
|
|
|
$ = require('$'), |
|
7
|
|
|
JSON = require('JSON'), |
|
|
|
|
|
|
8
|
|
|
Opentip = require('Opentip'), |
|
9
|
|
|
Pikaday = require('pikaday'), |
|
10
|
|
|
|
|
11
|
|
|
fDisposalTooltipHelper = function(oElement) { |
|
12
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
13
|
|
|
if (oElement && oElement.__opentip) |
|
14
|
|
|
{ |
|
15
|
|
|
oElement.__opentip.deactivate(); |
|
16
|
|
|
} |
|
17
|
|
|
}); |
|
18
|
|
|
}; |
|
19
|
|
|
|
|
20
|
|
|
ko.bindingHandlers.updateWidth = { |
|
21
|
|
|
init: function(oElement, fValueAccessor) { |
|
22
|
|
|
var |
|
23
|
|
|
$w = $(window), |
|
24
|
|
|
$oEl = $(oElement), |
|
25
|
|
|
fValue = fValueAccessor(), |
|
26
|
|
|
fInit = function() { |
|
27
|
|
|
fValue($oEl.width()); |
|
28
|
|
|
window.setTimeout(function() { |
|
29
|
|
|
fValue($oEl.width()); |
|
30
|
|
|
}, 500); |
|
31
|
|
|
}; |
|
32
|
|
|
|
|
33
|
|
|
$w.on('resize', fInit); |
|
34
|
|
|
fInit(); |
|
35
|
|
|
|
|
36
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
37
|
|
|
$w.off('resize', fInit); |
|
38
|
|
|
}); |
|
39
|
|
|
} |
|
40
|
|
|
}; |
|
41
|
|
|
|
|
42
|
|
|
ko.bindingHandlers.editor = { |
|
43
|
|
|
init: function(oElement, fValueAccessor) { |
|
44
|
|
|
|
|
45
|
|
|
var |
|
46
|
|
|
oEditor = null, |
|
47
|
|
|
fValue = fValueAccessor(), |
|
48
|
|
|
|
|
49
|
|
|
fUpdateEditorValue = function() { |
|
50
|
|
|
if (fValue && fValue.__editor) |
|
51
|
|
|
{ |
|
52
|
|
|
fValue.__editor.setHtmlOrPlain(fValue()); |
|
53
|
|
|
} |
|
54
|
|
|
}, |
|
55
|
|
|
|
|
56
|
|
|
fUpdateKoValue = function() { |
|
57
|
|
|
if (fValue && fValue.__editor) |
|
58
|
|
|
{ |
|
59
|
|
|
fValue(fValue.__editor.getDataWithHtmlMark()); |
|
60
|
|
|
} |
|
61
|
|
|
}, |
|
62
|
|
|
|
|
63
|
|
|
fOnReady = function() { |
|
64
|
|
|
fValue.__editor = oEditor; |
|
65
|
|
|
fUpdateEditorValue(); |
|
66
|
|
|
}, |
|
67
|
|
|
|
|
68
|
|
|
HtmlEditor = require('Common/HtmlEditor'); |
|
69
|
|
|
|
|
70
|
|
|
if (ko.isObservable(fValue) && HtmlEditor) |
|
71
|
|
|
{ |
|
72
|
|
|
oEditor = new HtmlEditor(oElement, fUpdateKoValue, fOnReady, fUpdateKoValue); |
|
73
|
|
|
|
|
74
|
|
|
fValue.__fetchEditorValue = fUpdateKoValue; |
|
75
|
|
|
|
|
76
|
|
|
fValue.subscribe(fUpdateEditorValue); |
|
77
|
|
|
|
|
78
|
|
|
// ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
79
|
|
|
// }); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
}; |
|
83
|
|
|
|
|
84
|
|
|
ko.bindingHandlers.json = { |
|
85
|
|
|
init: function(oElement, fValueAccessor) { |
|
86
|
|
|
$(oElement).text(JSON.stringify(ko.unwrap(fValueAccessor()))); |
|
87
|
|
|
}, |
|
88
|
|
|
update: function(oElement, fValueAccessor) { |
|
89
|
|
|
$(oElement).text(JSON.stringify(ko.unwrap(fValueAccessor()))); |
|
90
|
|
|
} |
|
91
|
|
|
}; |
|
92
|
|
|
|
|
93
|
|
|
ko.bindingHandlers.scrollerShadows = { |
|
94
|
|
|
init: function(oElement) { |
|
95
|
|
|
|
|
96
|
|
|
var |
|
97
|
|
|
iLimit = 8, |
|
98
|
|
|
$oEl = $(oElement), |
|
99
|
|
|
$win = $(window), |
|
100
|
|
|
oCont = $oEl.find('[data-scroller-shadows-content]')[0] || null, |
|
101
|
|
|
fFunc = _.throttle(function() { |
|
102
|
|
|
$oEl |
|
103
|
|
|
.toggleClass('scroller-shadow-top', iLimit < oCont.scrollTop) |
|
104
|
|
|
.toggleClass('scroller-shadow-bottom', oCont.scrollTop + iLimit < oCont.scrollHeight - oCont.clientHeight); |
|
105
|
|
|
}, 100); |
|
106
|
|
|
|
|
107
|
|
|
if (oCont) |
|
108
|
|
|
{ |
|
109
|
|
|
$(oCont).on('scroll resize', fFunc); |
|
110
|
|
|
$win.on('resize', fFunc); |
|
111
|
|
|
|
|
112
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oCont, function() { |
|
113
|
|
|
$(oCont).off(); |
|
114
|
|
|
$win.off('resize', fFunc); |
|
115
|
|
|
}); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
}; |
|
119
|
|
|
|
|
120
|
|
|
ko.bindingHandlers.pikaday = { |
|
121
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) { |
|
122
|
|
|
|
|
123
|
|
|
ko.bindingHandlers.textInput |
|
124
|
|
|
.init.apply(oViewModel, Array.prototype.slice.call(arguments)); // eslint-disable-line prefer-rest-params |
|
125
|
|
|
|
|
126
|
|
|
if (Pikaday) |
|
127
|
|
|
{ |
|
128
|
|
|
oElement.__pikaday = new Pikaday({ |
|
129
|
|
|
field: oElement |
|
130
|
|
|
}); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
}; |
|
134
|
|
|
|
|
135
|
|
|
ko.bindingHandlers.tooltip = { |
|
136
|
|
|
init: function(oElement, fValueAccessor) { |
|
137
|
|
|
|
|
138
|
|
|
var |
|
139
|
|
|
bi18n = true, |
|
|
|
|
|
|
140
|
|
|
sValue = '', |
|
141
|
|
|
Translator = null, |
|
142
|
|
|
$oEl = $(oElement), |
|
143
|
|
|
fValue = fValueAccessor(), |
|
144
|
|
|
bMobile = 'on' === ($oEl.data('tooltip-mobile') || 'off'), |
|
145
|
|
|
Globals = require('Common/Globals'); |
|
146
|
|
|
|
|
147
|
|
|
if (!Globals.bMobileDevice || bMobile) |
|
148
|
|
|
{ |
|
149
|
|
|
bi18n = 'on' === ($oEl.data('tooltip-i18n') || 'on'); |
|
150
|
|
|
sValue = !ko.isObservable(fValue) && _.isFunction(fValue) ? fValue() : ko.unwrap(fValue); |
|
151
|
|
|
|
|
152
|
|
|
oElement.__opentip = new Opentip(oElement, { |
|
153
|
|
|
'style': 'rainloopTip', |
|
154
|
|
|
'element': oElement, |
|
155
|
|
|
'tipJoint': $oEl.data('tooltip-join') || 'bottom' |
|
156
|
|
|
}); |
|
157
|
|
|
|
|
158
|
|
|
Globals.dropdownVisibility.subscribe(function(bV) { |
|
159
|
|
|
if (bV) { |
|
160
|
|
|
oElement.__opentip.hide(); |
|
161
|
|
|
} |
|
162
|
|
|
}); |
|
163
|
|
|
|
|
164
|
|
|
if ('' === sValue) |
|
165
|
|
|
{ |
|
166
|
|
|
oElement.__opentip.hide(); |
|
167
|
|
|
oElement.__opentip.deactivate(); |
|
168
|
|
|
oElement.__opentip.setContent(''); |
|
169
|
|
|
} |
|
170
|
|
|
else |
|
171
|
|
|
{ |
|
172
|
|
|
oElement.__opentip.activate(); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
if (bi18n) |
|
176
|
|
|
{ |
|
177
|
|
|
Translator = require('Common/Translator'); |
|
178
|
|
|
|
|
179
|
|
|
oElement.__opentip.setContent(Translator.i18n(sValue)); |
|
180
|
|
|
|
|
181
|
|
|
Translator.trigger.subscribe(function() { |
|
182
|
|
|
oElement.__opentip.setContent(Translator.i18n(sValue)); |
|
183
|
|
|
}); |
|
184
|
|
|
|
|
185
|
|
|
Globals.dropdownVisibility.subscribe(function() { |
|
186
|
|
|
if (oElement && oElement.__opentip) |
|
187
|
|
|
{ |
|
188
|
|
|
oElement.__opentip.setContent(require('Common/Translator').i18n(sValue)); |
|
189
|
|
|
} |
|
190
|
|
|
}); |
|
191
|
|
|
} |
|
192
|
|
|
else |
|
193
|
|
|
{ |
|
194
|
|
|
oElement.__opentip.setContent(sValue); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
}, |
|
198
|
|
|
update: function(oElement, fValueAccessor) { |
|
199
|
|
|
|
|
200
|
|
|
var |
|
201
|
|
|
bi18n = true, |
|
|
|
|
|
|
202
|
|
|
sValue = '', |
|
203
|
|
|
$oEl = $(oElement), |
|
204
|
|
|
fValue = fValueAccessor(), |
|
205
|
|
|
bMobile = 'on' === ($oEl.data('tooltip-mobile') || 'off'), |
|
206
|
|
|
Globals = require('Common/Globals'); |
|
207
|
|
|
|
|
208
|
|
|
if ((!Globals.bMobileDevice || bMobile) && oElement.__opentip) |
|
209
|
|
|
{ |
|
210
|
|
|
bi18n = 'on' === ($oEl.data('tooltip-i18n') || 'on'); |
|
211
|
|
|
sValue = !ko.isObservable(fValue) && _.isFunction(fValue) ? fValue() : ko.unwrap(fValue); |
|
212
|
|
|
|
|
213
|
|
|
if (sValue) |
|
214
|
|
|
{ |
|
215
|
|
|
oElement.__opentip.setContent( |
|
216
|
|
|
bi18n ? require('Common/Translator').i18n(sValue) : sValue); |
|
217
|
|
|
oElement.__opentip.activate(); |
|
218
|
|
|
} |
|
219
|
|
|
else |
|
220
|
|
|
{ |
|
221
|
|
|
oElement.__opentip.hide(); |
|
222
|
|
|
oElement.__opentip.deactivate(); |
|
223
|
|
|
oElement.__opentip.setContent(''); |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
}; |
|
228
|
|
|
|
|
229
|
|
|
ko.bindingHandlers.tooltipErrorTip = { |
|
230
|
|
|
init: function(oElement) { |
|
231
|
|
|
|
|
232
|
|
|
var $oEl = $(oElement); |
|
233
|
|
|
|
|
234
|
|
|
oElement.__opentip = new Opentip(oElement, { |
|
235
|
|
|
'style': 'rainloopErrorTip', |
|
236
|
|
|
'hideOn': 'mouseout click', |
|
237
|
|
|
'element': oElement, |
|
238
|
|
|
'tipJoint': $oEl.data('tooltip-join') || 'top' |
|
239
|
|
|
}); |
|
240
|
|
|
|
|
241
|
|
|
oElement.__opentip.deactivate(); |
|
242
|
|
|
|
|
243
|
|
|
$(window.document).on('click', function() { |
|
244
|
|
|
if (oElement && oElement.__opentip) |
|
245
|
|
|
{ |
|
246
|
|
|
oElement.__opentip.hide(); |
|
247
|
|
|
} |
|
248
|
|
|
}); |
|
249
|
|
|
|
|
250
|
|
|
fDisposalTooltipHelper(oElement); |
|
251
|
|
|
}, |
|
252
|
|
|
update: function(oElement, fValueAccessor) { |
|
253
|
|
|
|
|
254
|
|
|
var |
|
255
|
|
|
$oEl = $(oElement), |
|
256
|
|
|
fValue = fValueAccessor(), |
|
257
|
|
|
sValue = !ko.isObservable(fValue) && _.isFunction(fValue) ? fValue() : ko.unwrap(fValue), |
|
258
|
|
|
oOpenTips = oElement.__opentip; |
|
259
|
|
|
|
|
260
|
|
|
if (oOpenTips) |
|
261
|
|
|
{ |
|
262
|
|
|
if ('' === sValue) |
|
263
|
|
|
{ |
|
264
|
|
|
oOpenTips.hide(); |
|
265
|
|
|
oOpenTips.deactivate(); |
|
266
|
|
|
oOpenTips.setContent(''); |
|
267
|
|
|
} |
|
268
|
|
|
else |
|
269
|
|
|
{ |
|
270
|
|
|
_.delay(function() { |
|
271
|
|
|
if ($oEl.is(':visible')) |
|
272
|
|
|
{ |
|
273
|
|
|
oOpenTips.setContent(sValue); |
|
274
|
|
|
oOpenTips.activate(); |
|
275
|
|
|
oOpenTips.show(); |
|
276
|
|
|
} |
|
277
|
|
|
else |
|
278
|
|
|
{ |
|
279
|
|
|
oOpenTips.hide(); |
|
280
|
|
|
oOpenTips.deactivate(); |
|
281
|
|
|
oOpenTips.setContent(''); |
|
282
|
|
|
} |
|
283
|
|
|
}, 100); |
|
284
|
|
|
} |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
}; |
|
288
|
|
|
|
|
289
|
|
|
ko.bindingHandlers.registrateBootstrapDropdown = { |
|
290
|
|
|
init: function(oElement) { |
|
291
|
|
|
var Globals = require('Common/Globals'); |
|
292
|
|
|
if (Globals && Globals.data.aBootstrapDropdowns) |
|
293
|
|
|
{ |
|
294
|
|
|
Globals.data.aBootstrapDropdowns.push($(oElement)); |
|
295
|
|
|
|
|
296
|
|
|
$(oElement).click(function() { |
|
297
|
|
|
require('Common/Utils').detectDropdownVisibility(); |
|
298
|
|
|
}); |
|
299
|
|
|
|
|
300
|
|
|
// ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
301
|
|
|
// }); |
|
302
|
|
|
} |
|
303
|
|
|
} |
|
304
|
|
|
}; |
|
305
|
|
|
|
|
306
|
|
|
ko.bindingHandlers.openDropdownTrigger = { |
|
307
|
|
|
update: function(oElement, fValueAccessor) { |
|
308
|
|
|
if (ko.unwrap(fValueAccessor())) |
|
309
|
|
|
{ |
|
310
|
|
|
var $oEl = $(oElement); |
|
311
|
|
|
if (!$oEl.hasClass('open')) |
|
312
|
|
|
{ |
|
313
|
|
|
$oEl.find('.dropdown-toggle').dropdown('toggle'); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
$oEl.find('.dropdown-toggle').focus(); |
|
317
|
|
|
|
|
318
|
|
|
require('Common/Utils').detectDropdownVisibility(); |
|
319
|
|
|
fValueAccessor()(false); |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
}; |
|
323
|
|
|
|
|
324
|
|
|
ko.bindingHandlers.dropdownCloser = { |
|
325
|
|
|
init: function(oElement) { |
|
326
|
|
|
$(oElement).closest('.dropdown').on('click', '.e-item', function() { |
|
327
|
|
|
$(oElement).dropdown('toggle'); |
|
328
|
|
|
}); |
|
329
|
|
|
} |
|
330
|
|
|
}; |
|
331
|
|
|
|
|
332
|
|
|
ko.bindingHandlers.popover = { |
|
333
|
|
|
init: function(oElement, fValueAccessor) { |
|
334
|
|
|
$(oElement).popover(ko.unwrap(fValueAccessor())); |
|
335
|
|
|
|
|
336
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
337
|
|
|
$(oElement).popover('destroy'); |
|
338
|
|
|
}); |
|
339
|
|
|
} |
|
340
|
|
|
}; |
|
341
|
|
|
|
|
342
|
|
|
ko.bindingHandlers.csstext = {}; |
|
343
|
|
|
ko.bindingHandlers.csstext.init = ko.bindingHandlers.csstext.update = function(oElement, fValueAccessor) { |
|
344
|
|
|
if (oElement && oElement.styleSheet && 'undefined' !== typeof oElement.styleSheet.cssText) |
|
345
|
|
|
{ |
|
346
|
|
|
oElement.styleSheet.cssText = ko.unwrap(fValueAccessor()); |
|
347
|
|
|
} |
|
348
|
|
|
else |
|
349
|
|
|
{ |
|
350
|
|
|
$(oElement).text(ko.unwrap(fValueAccessor())); |
|
351
|
|
|
} |
|
352
|
|
|
}; |
|
353
|
|
|
|
|
354
|
|
|
ko.bindingHandlers.resizecrop = { |
|
355
|
|
|
init: function(oElement) { |
|
356
|
|
|
$(oElement).addClass('resizecrop').resizecrop({ |
|
357
|
|
|
'width': '100', |
|
358
|
|
|
'height': '100', |
|
359
|
|
|
'wrapperCSS': { |
|
360
|
|
|
'border-radius': '10px' |
|
361
|
|
|
} |
|
362
|
|
|
}); |
|
363
|
|
|
}, |
|
364
|
|
|
update: function(oElement, fValueAccessor) { |
|
365
|
|
|
fValueAccessor()(); |
|
366
|
|
|
$(oElement).resizecrop({ |
|
367
|
|
|
'width': '100', |
|
368
|
|
|
'height': '100' |
|
369
|
|
|
}); |
|
370
|
|
|
} |
|
371
|
|
|
}; |
|
372
|
|
|
|
|
373
|
|
|
ko.bindingHandlers.onEnter = { |
|
374
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) { |
|
375
|
|
|
$(oElement).on('keypress.koOnEnter', function(oEvent) { |
|
376
|
|
|
if (oEvent && 13 === window.parseInt(oEvent.keyCode, 10)) |
|
377
|
|
|
{ |
|
378
|
|
|
$(oElement).trigger('change'); |
|
379
|
|
|
fValueAccessor().call(oViewModel); |
|
380
|
|
|
} |
|
381
|
|
|
}); |
|
382
|
|
|
|
|
383
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
384
|
|
|
$(oElement).off('keypress.koOnEnter'); |
|
385
|
|
|
}); |
|
386
|
|
|
} |
|
387
|
|
|
}; |
|
388
|
|
|
|
|
389
|
|
|
ko.bindingHandlers.onSpace = { |
|
390
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) { |
|
391
|
|
|
$(oElement).on('keyup.koOnSpace', function(oEvent) { |
|
392
|
|
|
if (oEvent && 32 === window.parseInt(oEvent.keyCode, 10)) |
|
393
|
|
|
{ |
|
394
|
|
|
fValueAccessor().call(oViewModel, oEvent); |
|
395
|
|
|
} |
|
396
|
|
|
}); |
|
397
|
|
|
|
|
398
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
399
|
|
|
$(oElement).off('keyup.koOnSpace'); |
|
400
|
|
|
}); |
|
401
|
|
|
} |
|
402
|
|
|
}; |
|
403
|
|
|
|
|
404
|
|
|
ko.bindingHandlers.onTab = { |
|
405
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) { |
|
406
|
|
|
$(oElement).on('keydown.koOnTab', function(oEvent) { |
|
407
|
|
|
if (oEvent && 9 === window.parseInt(oEvent.keyCode, 10)) |
|
408
|
|
|
{ |
|
409
|
|
|
return fValueAccessor().call(oViewModel, !!oEvent.shiftKey); |
|
410
|
|
|
} |
|
411
|
|
|
return true; |
|
412
|
|
|
}); |
|
413
|
|
|
|
|
414
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
415
|
|
|
$(oElement).off('keydown.koOnTab'); |
|
416
|
|
|
}); |
|
417
|
|
|
} |
|
418
|
|
|
}; |
|
419
|
|
|
|
|
420
|
|
|
ko.bindingHandlers.onEsc = { |
|
421
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) { |
|
422
|
|
|
$(oElement).on('keypress.koOnEsc', function(oEvent) { |
|
423
|
|
|
if (oEvent && 27 === window.parseInt(oEvent.keyCode, 10)) |
|
424
|
|
|
{ |
|
425
|
|
|
$(oElement).trigger('change'); |
|
426
|
|
|
fValueAccessor().call(oViewModel); |
|
427
|
|
|
} |
|
428
|
|
|
}); |
|
429
|
|
|
|
|
430
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
431
|
|
|
$(oElement).off('keypress.koOnEsc'); |
|
432
|
|
|
}); |
|
433
|
|
|
} |
|
434
|
|
|
}; |
|
435
|
|
|
|
|
436
|
|
|
ko.bindingHandlers.clickOnTrue = { |
|
437
|
|
|
update: function(oElement, fValueAccessor) { |
|
438
|
|
|
if (ko.unwrap(fValueAccessor())) |
|
439
|
|
|
{ |
|
440
|
|
|
$(oElement).click(); |
|
441
|
|
|
} |
|
442
|
|
|
} |
|
443
|
|
|
}; |
|
444
|
|
|
|
|
445
|
|
|
ko.bindingHandlers.modal = { |
|
446
|
|
|
init: function(oElement, fValueAccessor) { |
|
447
|
|
|
|
|
448
|
|
|
var |
|
449
|
|
|
Globals = require('Common/Globals'), |
|
450
|
|
|
Utils = require('Common/Utils'); |
|
451
|
|
|
|
|
452
|
|
|
$(oElement) |
|
453
|
|
|
.toggleClass('fade', !Globals.bMobileDevice) |
|
454
|
|
|
.modal({ |
|
455
|
|
|
'keyboard': false, |
|
456
|
|
|
'show': ko.unwrap(fValueAccessor()) |
|
457
|
|
|
}) |
|
458
|
|
|
.on('shown.koModal', Utils.windowResizeCallback) |
|
459
|
|
|
.find('.close').on('click.koModal', function() { |
|
460
|
|
|
fValueAccessor()(false); |
|
461
|
|
|
}); |
|
462
|
|
|
|
|
463
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
464
|
|
|
$(oElement) |
|
465
|
|
|
.off('shown.koModal') |
|
466
|
|
|
.find('.close') |
|
467
|
|
|
.off('click.koModal'); |
|
468
|
|
|
}); |
|
469
|
|
|
}, |
|
470
|
|
|
update: function(oElement, fValueAccessor) { |
|
471
|
|
|
|
|
472
|
|
|
var Globals = require('Common/Globals'); |
|
473
|
|
|
|
|
474
|
|
|
$(oElement).modal(ko.unwrap(fValueAccessor()) ? 'show' : 'hide'); |
|
475
|
|
|
|
|
476
|
|
|
if (Globals.$html.hasClass('rl-anim')) |
|
477
|
|
|
{ |
|
478
|
|
|
Globals.$html.addClass('rl-modal-animation'); |
|
479
|
|
|
_.delay(function() { |
|
480
|
|
|
Globals.$html.removeClass('rl-modal-animation'); |
|
481
|
|
|
}, 400); |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
} |
|
485
|
|
|
}; |
|
486
|
|
|
|
|
487
|
|
|
ko.bindingHandlers.moment = { |
|
488
|
|
|
init: function(oElement, fValueAccessor) { |
|
489
|
|
|
require('Common/Momentor').momentToNode( |
|
490
|
|
|
$(oElement).addClass('moment').data('moment-time', ko.unwrap(fValueAccessor())) |
|
491
|
|
|
); |
|
492
|
|
|
}, |
|
493
|
|
|
update: function(oElement, fValueAccessor) { |
|
494
|
|
|
require('Common/Momentor').momentToNode( |
|
495
|
|
|
$(oElement).data('moment-time', ko.unwrap(fValueAccessor())) |
|
496
|
|
|
); |
|
497
|
|
|
} |
|
498
|
|
|
}; |
|
499
|
|
|
|
|
500
|
|
|
ko.bindingHandlers.i18nInit = { |
|
501
|
|
|
init: function(oElement) { |
|
502
|
|
|
require('Common/Translator').i18nToNodes(oElement); |
|
503
|
|
|
} |
|
504
|
|
|
}; |
|
505
|
|
|
|
|
506
|
|
|
ko.bindingHandlers.translatorInit = { |
|
507
|
|
|
init: function(oElement) { |
|
508
|
|
|
require('Common/Translator').i18nToNodes(oElement); |
|
509
|
|
|
} |
|
510
|
|
|
}; |
|
511
|
|
|
|
|
512
|
|
|
ko.bindingHandlers.i18nUpdate = { |
|
513
|
|
|
update: function(oElement, fValueAccessor) { |
|
514
|
|
|
ko.unwrap(fValueAccessor()); |
|
515
|
|
|
require('Common/Translator').i18nToNodes(oElement); |
|
516
|
|
|
} |
|
517
|
|
|
}; |
|
518
|
|
|
|
|
519
|
|
|
ko.bindingHandlers.link = { |
|
520
|
|
|
update: function(oElement, fValueAccessor) { |
|
521
|
|
|
$(oElement).attr('href', ko.unwrap(fValueAccessor())); |
|
522
|
|
|
} |
|
523
|
|
|
}; |
|
524
|
|
|
|
|
525
|
|
|
ko.bindingHandlers.title = { |
|
526
|
|
|
update: function(oElement, fValueAccessor) { |
|
527
|
|
|
$(oElement).attr('title', ko.unwrap(fValueAccessor())); |
|
528
|
|
|
} |
|
529
|
|
|
}; |
|
530
|
|
|
|
|
531
|
|
|
ko.bindingHandlers.textF = { |
|
532
|
|
|
init: function(oElement, fValueAccessor) { |
|
533
|
|
|
$(oElement).text(ko.unwrap(fValueAccessor())); |
|
534
|
|
|
} |
|
535
|
|
|
}; |
|
536
|
|
|
|
|
537
|
|
|
ko.bindingHandlers.initDom = { |
|
538
|
|
|
init: function(oElement, fValueAccessor) { |
|
539
|
|
|
fValueAccessor()(oElement); |
|
540
|
|
|
} |
|
541
|
|
|
}; |
|
542
|
|
|
|
|
543
|
|
|
ko.bindingHandlers.initFixedTrigger = { |
|
544
|
|
|
init: function(oElement, fValueAccessor) { |
|
545
|
|
|
var |
|
546
|
|
|
aValues = ko.unwrap(fValueAccessor()), |
|
547
|
|
|
$oContainer = null, |
|
548
|
|
|
$oElement = $(oElement), |
|
549
|
|
|
oOffset = null, |
|
550
|
|
|
|
|
551
|
|
|
iTop = aValues[1] || 0; |
|
552
|
|
|
|
|
553
|
|
|
$oContainer = $(aValues[0] || null); |
|
554
|
|
|
$oContainer = $oContainer[0] ? $oContainer : null; |
|
555
|
|
|
|
|
556
|
|
|
if ($oContainer) |
|
557
|
|
|
{ |
|
558
|
|
|
$(window).resize(function() { |
|
559
|
|
|
oOffset = $oContainer.offset(); |
|
560
|
|
|
if (oOffset && oOffset.top) |
|
561
|
|
|
{ |
|
562
|
|
|
$oElement.css('top', oOffset.top + iTop); |
|
563
|
|
|
} |
|
564
|
|
|
}); |
|
565
|
|
|
} |
|
566
|
|
|
} |
|
567
|
|
|
}; |
|
568
|
|
|
|
|
569
|
|
|
ko.bindingHandlers.initResizeTrigger = { |
|
570
|
|
|
init: function(oElement, fValueAccessor) { |
|
571
|
|
|
var aValues = ko.unwrap(fValueAccessor()); |
|
572
|
|
|
$(oElement).css({ |
|
573
|
|
|
'height': aValues[1], |
|
574
|
|
|
'min-height': aValues[1] |
|
575
|
|
|
}); |
|
576
|
|
|
}, |
|
577
|
|
|
update: function(oElement, fValueAccessor) { |
|
578
|
|
|
|
|
579
|
|
|
var |
|
580
|
|
|
Utils = require('Common/Utils'), |
|
581
|
|
|
Globals = require('Common/Globals'), |
|
582
|
|
|
aValues = ko.unwrap(fValueAccessor()), |
|
583
|
|
|
iValue = Utils.pInt(aValues[1]), |
|
584
|
|
|
iSize = 0, |
|
585
|
|
|
iOffset = $(oElement).offset().top; |
|
586
|
|
|
|
|
587
|
|
|
if (0 < iOffset) |
|
588
|
|
|
{ |
|
589
|
|
|
iOffset += Utils.pInt(aValues[2]); |
|
590
|
|
|
iSize = Globals.$win.height() - iOffset; |
|
591
|
|
|
|
|
592
|
|
|
if (iValue < iSize) |
|
593
|
|
|
{ |
|
594
|
|
|
iValue = iSize; |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
$(oElement).css({ |
|
598
|
|
|
'height': iValue, |
|
599
|
|
|
'min-height': iValue |
|
600
|
|
|
}); |
|
601
|
|
|
} |
|
602
|
|
|
} |
|
603
|
|
|
}; |
|
604
|
|
|
|
|
605
|
|
|
ko.bindingHandlers.appendDom = { |
|
606
|
|
|
update: function(oElement, fValueAccessor) { |
|
607
|
|
|
$(oElement).hide().empty().append(ko.unwrap(fValueAccessor())).show(); |
|
608
|
|
|
} |
|
609
|
|
|
}; |
|
610
|
|
|
|
|
611
|
|
|
ko.bindingHandlers.draggable = { |
|
612
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor) { |
|
613
|
|
|
|
|
614
|
|
|
var |
|
615
|
|
|
Globals = require('Common/Globals'), |
|
616
|
|
|
Utils = require('Common/Utils'); |
|
617
|
|
|
|
|
618
|
|
|
if (!Globals.bMobileDevice) |
|
619
|
|
|
{ |
|
620
|
|
|
var |
|
621
|
|
|
iTriggerZone = 100, |
|
622
|
|
|
iScrollSpeed = 3, |
|
623
|
|
|
fAllValueFunc = fAllBindingsAccessor(), |
|
624
|
|
|
sDroppableSelector = fAllValueFunc && fAllValueFunc.droppableSelector ? fAllValueFunc.droppableSelector : '', |
|
625
|
|
|
oConf = { |
|
626
|
|
|
distance: 20, |
|
627
|
|
|
handle: '.dragHandle', |
|
628
|
|
|
cursorAt: {top: 22, left: 3}, |
|
629
|
|
|
refreshPositions: true, |
|
630
|
|
|
scroll: true |
|
631
|
|
|
}; |
|
632
|
|
|
|
|
633
|
|
|
if (sDroppableSelector) |
|
634
|
|
|
{ |
|
635
|
|
|
oConf.drag = function(oEvent) { |
|
636
|
|
|
|
|
637
|
|
|
$(sDroppableSelector).each(function() { |
|
638
|
|
|
var |
|
639
|
|
|
moveUp = null, |
|
|
|
|
|
|
640
|
|
|
moveDown = null, |
|
|
|
|
|
|
641
|
|
|
$this = $(this), |
|
642
|
|
|
oOffset = $this.offset(), |
|
643
|
|
|
bottomPos = oOffset.top + $this.height(); |
|
644
|
|
|
|
|
645
|
|
|
window.clearInterval($this.data('timerScroll')); |
|
646
|
|
|
$this.data('timerScroll', false); |
|
647
|
|
|
|
|
648
|
|
|
if (oEvent.pageX >= oOffset.left && oEvent.pageX <= oOffset.left + $this.width()) |
|
649
|
|
|
{ |
|
650
|
|
|
if (oEvent.pageY >= bottomPos - iTriggerZone && oEvent.pageY <= bottomPos) |
|
651
|
|
|
{ |
|
652
|
|
|
moveUp = function() { |
|
653
|
|
|
$this.scrollTop($this.scrollTop() + iScrollSpeed); |
|
654
|
|
|
Utils.windowResize(); |
|
655
|
|
|
}; |
|
656
|
|
|
|
|
657
|
|
|
$this.data('timerScroll', window.setInterval(moveUp, 10)); |
|
658
|
|
|
moveUp(); |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
if (oEvent.pageY >= oOffset.top && oEvent.pageY <= oOffset.top + iTriggerZone) |
|
662
|
|
|
{ |
|
663
|
|
|
moveDown = function() { |
|
664
|
|
|
$this.scrollTop($this.scrollTop() - iScrollSpeed); |
|
665
|
|
|
Utils.windowResize(); |
|
666
|
|
|
}; |
|
667
|
|
|
|
|
668
|
|
|
$this.data('timerScroll', window.setInterval(moveDown, 10)); |
|
669
|
|
|
moveDown(); |
|
670
|
|
|
} |
|
671
|
|
|
} |
|
672
|
|
|
}); |
|
673
|
|
|
}; |
|
674
|
|
|
|
|
675
|
|
|
oConf.stop = function() { |
|
676
|
|
|
$(sDroppableSelector).each(function() { |
|
677
|
|
|
window.clearInterval($(this).data('timerScroll')); |
|
678
|
|
|
$(this).data('timerScroll', false); |
|
679
|
|
|
}); |
|
680
|
|
|
}; |
|
681
|
|
|
} |
|
682
|
|
|
|
|
683
|
|
|
oConf.helper = function(oEvent) { |
|
684
|
|
|
return fValueAccessor()(oEvent && oEvent.target ? ko.dataFor(oEvent.target) : null); |
|
685
|
|
|
}; |
|
686
|
|
|
|
|
687
|
|
|
$(oElement).draggable(oConf).on('mousedown.koDraggable', function() { |
|
688
|
|
|
Utils.removeInFocus(); |
|
689
|
|
|
}); |
|
690
|
|
|
|
|
691
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
692
|
|
|
$(oElement) |
|
693
|
|
|
.off('mousedown.koDraggable') |
|
694
|
|
|
.draggable('destroy'); |
|
695
|
|
|
}); |
|
696
|
|
|
} |
|
697
|
|
|
} |
|
698
|
|
|
}; |
|
699
|
|
|
|
|
700
|
|
|
ko.bindingHandlers.droppable = { |
|
701
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor) { |
|
702
|
|
|
var Globals = require('Common/Globals'); |
|
703
|
|
|
if (!Globals.bMobileDevice) |
|
704
|
|
|
{ |
|
705
|
|
|
var |
|
706
|
|
|
fValueFunc = fValueAccessor(), |
|
707
|
|
|
fAllValueFunc = fAllBindingsAccessor(), |
|
708
|
|
|
fOverCallback = fAllValueFunc && fAllValueFunc.droppableOver ? fAllValueFunc.droppableOver : null, |
|
709
|
|
|
fOutCallback = fAllValueFunc && fAllValueFunc.droppableOut ? fAllValueFunc.droppableOut : null, |
|
710
|
|
|
oConf = { |
|
711
|
|
|
tolerance: 'pointer', |
|
712
|
|
|
hoverClass: 'droppableHover' |
|
713
|
|
|
}; |
|
714
|
|
|
|
|
715
|
|
|
if (fValueFunc) |
|
716
|
|
|
{ |
|
717
|
|
|
oConf.drop = function(oEvent, oUi) { |
|
718
|
|
|
fValueFunc(oEvent, oUi); |
|
719
|
|
|
}; |
|
720
|
|
|
|
|
721
|
|
|
if (fOverCallback) |
|
722
|
|
|
{ |
|
723
|
|
|
oConf.over = function(oEvent, oUi) { |
|
724
|
|
|
fOverCallback(oEvent, oUi); |
|
725
|
|
|
}; |
|
726
|
|
|
} |
|
727
|
|
|
|
|
728
|
|
|
if (fOutCallback) |
|
729
|
|
|
{ |
|
730
|
|
|
oConf.out = function(oEvent, oUi) { |
|
731
|
|
|
fOutCallback(oEvent, oUi); |
|
732
|
|
|
}; |
|
733
|
|
|
} |
|
734
|
|
|
|
|
735
|
|
|
$(oElement).droppable(oConf); |
|
736
|
|
|
|
|
737
|
|
|
ko.utils.domNodeDisposal.addDisposeCallback(oElement, function() { |
|
738
|
|
|
$(oElement).droppable('destroy'); |
|
739
|
|
|
}); |
|
740
|
|
|
} |
|
741
|
|
|
} |
|
742
|
|
|
} |
|
743
|
|
|
}; |
|
744
|
|
|
|
|
745
|
|
|
ko.bindingHandlers.nano = { |
|
746
|
|
|
init: function(oElement) { |
|
747
|
|
|
|
|
748
|
|
|
var |
|
749
|
|
|
Globals = require('Common/Globals'), |
|
750
|
|
|
Settings = require('Storage/Settings'); |
|
751
|
|
|
|
|
752
|
|
|
if (!Globals.bDisableNanoScroll && !Settings.appSettingsGet('useNativeScrollbars')) |
|
753
|
|
|
{ |
|
754
|
|
|
$(oElement) |
|
755
|
|
|
.addClass('nano') |
|
756
|
|
|
.nanoScroller({ |
|
757
|
|
|
'iOSNativeScrolling': false, |
|
758
|
|
|
'preventPageScrolling': true |
|
759
|
|
|
}); |
|
760
|
|
|
} |
|
761
|
|
|
} |
|
762
|
|
|
}; |
|
763
|
|
|
|
|
764
|
|
|
ko.bindingHandlers.saveTrigger = { |
|
765
|
|
|
init: function(oElement) { |
|
766
|
|
|
|
|
767
|
|
|
var $oEl = $(oElement); |
|
768
|
|
|
|
|
769
|
|
|
$oEl.data('save-trigger-type', $oEl.is('input[type=text],input[type=email],input[type=password],select,textarea') ? 'input' : 'custom'); |
|
770
|
|
|
|
|
771
|
|
|
if ('custom' === $oEl.data('save-trigger-type')) |
|
772
|
|
|
{ |
|
773
|
|
|
$oEl.append( |
|
774
|
|
|
' <i class="icon-spinner animated"></i><i class="icon-remove error"></i><i class="icon-ok success"></i>' |
|
775
|
|
|
).addClass('settings-saved-trigger'); |
|
776
|
|
|
} |
|
777
|
|
|
else |
|
778
|
|
|
{ |
|
779
|
|
|
$oEl.addClass('settings-saved-trigger-input'); |
|
780
|
|
|
} |
|
781
|
|
|
}, |
|
782
|
|
|
update: function(oElement, fValueAccessor) { |
|
783
|
|
|
var |
|
784
|
|
|
mValue = ko.unwrap(fValueAccessor()), |
|
785
|
|
|
$oEl = $(oElement); |
|
786
|
|
|
|
|
787
|
|
|
if ('custom' === $oEl.data('save-trigger-type')) |
|
788
|
|
|
{ |
|
789
|
|
|
switch (mValue.toString()) |
|
790
|
|
|
{ |
|
791
|
|
|
case '1': |
|
792
|
|
|
$oEl |
|
793
|
|
|
.find('.animated,.error').hide().removeClass('visible') |
|
794
|
|
|
.end() |
|
795
|
|
|
.find('.success').show().addClass('visible'); |
|
796
|
|
|
break; |
|
797
|
|
|
case '0': |
|
798
|
|
|
$oEl |
|
799
|
|
|
.find('.animated,.success').hide().removeClass('visible') |
|
800
|
|
|
.end() |
|
801
|
|
|
.find('.error').show().addClass('visible'); |
|
802
|
|
|
break; |
|
803
|
|
|
case '-2': |
|
804
|
|
|
$oEl |
|
805
|
|
|
.find('.error,.success').hide().removeClass('visible') |
|
806
|
|
|
.end() |
|
807
|
|
|
.find('.animated').show().addClass('visible'); |
|
808
|
|
|
break; |
|
809
|
|
|
default: |
|
810
|
|
|
$oEl |
|
811
|
|
|
.find('.animated').hide() |
|
812
|
|
|
.end() |
|
813
|
|
|
.find('.error,.success').removeClass('visible'); |
|
814
|
|
|
break; |
|
815
|
|
|
} |
|
816
|
|
|
} |
|
817
|
|
|
else |
|
818
|
|
|
{ |
|
819
|
|
|
switch (mValue.toString()) |
|
820
|
|
|
{ |
|
821
|
|
|
case '1': |
|
822
|
|
|
$oEl.addClass('success').removeClass('error'); |
|
823
|
|
|
break; |
|
824
|
|
|
case '0': |
|
825
|
|
|
$oEl.addClass('error').removeClass('success'); |
|
826
|
|
|
break; |
|
827
|
|
|
case '-2': |
|
828
|
|
|
// $oEl; |
|
829
|
|
|
break; |
|
830
|
|
|
default: |
|
831
|
|
|
$oEl.removeClass('error success'); |
|
832
|
|
|
break; |
|
833
|
|
|
} |
|
834
|
|
|
} |
|
835
|
|
|
} |
|
836
|
|
|
}; |
|
837
|
|
|
|
|
838
|
|
|
ko.bindingHandlers.emailsTags = { |
|
839
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor) { |
|
840
|
|
|
|
|
841
|
|
|
var |
|
842
|
|
|
Utils = require('Common/Utils'), |
|
843
|
|
|
EmailModel = require('Model/Email').default, |
|
844
|
|
|
|
|
845
|
|
|
$oEl = $(oElement), |
|
846
|
|
|
fValue = fValueAccessor(), |
|
847
|
|
|
fAllBindings = fAllBindingsAccessor(), |
|
848
|
|
|
fAutoCompleteSource = fAllBindings.autoCompleteSource || null, |
|
849
|
|
|
fFocusCallback = function(bValue) { |
|
850
|
|
|
if (fValue && fValue.focused) |
|
851
|
|
|
{ |
|
852
|
|
|
fValue.focused(!!bValue); |
|
853
|
|
|
} |
|
854
|
|
|
}; |
|
855
|
|
|
|
|
856
|
|
|
$oEl.inputosaurus({ |
|
857
|
|
|
'parseOnBlur': true, |
|
858
|
|
|
'allowDragAndDrop': true, |
|
859
|
|
|
'focusCallback': fFocusCallback, |
|
860
|
|
|
'inputDelimiters': [',', ';', '\n'], |
|
861
|
|
|
'autoCompleteSource': fAutoCompleteSource, |
|
862
|
|
|
// 'elementHook': function(oEl, oItem) { |
|
863
|
|
|
// if (oEl && oItem) |
|
864
|
|
|
// { |
|
865
|
|
|
// oEl.addClass('pgp'); |
|
866
|
|
|
// window.console.log(arguments); |
|
867
|
|
|
// } |
|
868
|
|
|
// }, |
|
869
|
|
|
'parseHook': function(aInput) { |
|
870
|
|
|
|
|
871
|
|
|
return _.map(aInput, function(sInputValue) { |
|
872
|
|
|
|
|
873
|
|
|
var |
|
874
|
|
|
sValue = Utils.trim(sInputValue), |
|
875
|
|
|
oEmail = null; |
|
|
|
|
|
|
876
|
|
|
|
|
877
|
|
|
if ('' !== sValue) |
|
878
|
|
|
{ |
|
879
|
|
|
oEmail = new EmailModel(); |
|
880
|
|
|
oEmail.mailsoParse(sValue); |
|
881
|
|
|
return [oEmail.toLine(false), oEmail]; |
|
882
|
|
|
} |
|
883
|
|
|
|
|
884
|
|
|
return [sValue, null]; |
|
885
|
|
|
|
|
886
|
|
|
}); |
|
887
|
|
|
|
|
888
|
|
|
// var aResult = []; |
|
889
|
|
|
// |
|
890
|
|
|
// _.each(aInput, function(sInputValue) { |
|
891
|
|
|
// |
|
892
|
|
|
// var |
|
893
|
|
|
// aM = null, |
|
894
|
|
|
// aValues = [], |
|
895
|
|
|
// sValue = Utils.trim(sInputValue), |
|
896
|
|
|
// oEmail = null |
|
897
|
|
|
// ; |
|
898
|
|
|
// |
|
899
|
|
|
// if ('' !== sValue) |
|
900
|
|
|
// { |
|
901
|
|
|
// aM = sValue.match(/[@]/g); |
|
902
|
|
|
// if (aM && 0 < aM.length) |
|
903
|
|
|
// { |
|
904
|
|
|
// sValue = sValue.replace(/[\r\n]+/g, '; ').replace(/[\s]+/g, ' '); |
|
905
|
|
|
// aValues = EmailModel.splitHelper(sValue, ';'); |
|
906
|
|
|
// |
|
907
|
|
|
// _.each(aValues, function(sV) { |
|
908
|
|
|
// |
|
909
|
|
|
// oEmail = new EmailModel(); |
|
910
|
|
|
// oEmail.mailsoParse(sV); |
|
911
|
|
|
// |
|
912
|
|
|
// if (oEmail.email) |
|
913
|
|
|
// { |
|
914
|
|
|
// aResult.push([oEmail.toLine(false), oEmail]); |
|
915
|
|
|
// } |
|
916
|
|
|
// else |
|
917
|
|
|
// { |
|
918
|
|
|
// aResult.push(['', null]); |
|
919
|
|
|
// } |
|
920
|
|
|
// }); |
|
921
|
|
|
// } |
|
922
|
|
|
// else |
|
923
|
|
|
// { |
|
924
|
|
|
// aResult.push([sInputValue, null]); |
|
925
|
|
|
// } |
|
926
|
|
|
// } |
|
927
|
|
|
// else |
|
928
|
|
|
// { |
|
929
|
|
|
// aResult.push([sInputValue, null]); |
|
930
|
|
|
// } |
|
931
|
|
|
// }); |
|
932
|
|
|
// |
|
933
|
|
|
// return aResult; |
|
934
|
|
|
}, |
|
935
|
|
|
'change': _.bind(function(oEvent) { |
|
936
|
|
|
$oEl.data('EmailsTagsValue', oEvent.target.value); |
|
937
|
|
|
fValue(oEvent.target.value); |
|
938
|
|
|
}, this) |
|
939
|
|
|
}); |
|
940
|
|
|
|
|
941
|
|
|
if (fValue && fValue.focused && fValue.focused.subscribe) |
|
942
|
|
|
{ |
|
943
|
|
|
fValue.focused.subscribe(function(bValue) { |
|
944
|
|
|
$oEl.inputosaurus(bValue ? 'focus' : 'blur'); |
|
945
|
|
|
}); |
|
946
|
|
|
} |
|
947
|
|
|
}, |
|
948
|
|
|
update: function(oElement, fValueAccessor) { |
|
949
|
|
|
|
|
950
|
|
|
var |
|
951
|
|
|
$oEl = $(oElement), |
|
952
|
|
|
fValue = fValueAccessor(), |
|
953
|
|
|
sValue = ko.unwrap(fValue); |
|
954
|
|
|
|
|
955
|
|
|
if ($oEl.data('EmailsTagsValue') !== sValue) |
|
956
|
|
|
{ |
|
957
|
|
|
$oEl.val(sValue); |
|
958
|
|
|
$oEl.data('EmailsTagsValue', sValue); |
|
959
|
|
|
$oEl.inputosaurus('refresh'); |
|
960
|
|
|
} |
|
961
|
|
|
} |
|
962
|
|
|
}; |
|
963
|
|
|
|
|
964
|
|
|
ko.bindingHandlers.command = { |
|
965
|
|
|
init: function(oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) { |
|
966
|
|
|
var |
|
967
|
|
|
jqElement = $(oElement), |
|
968
|
|
|
oCommand = fValueAccessor(); |
|
969
|
|
|
|
|
970
|
|
|
if (!oCommand || !oCommand.enabled || !oCommand.canExecute) |
|
971
|
|
|
{ |
|
972
|
|
|
throw new Error('You are not using command function'); |
|
973
|
|
|
} |
|
974
|
|
|
|
|
975
|
|
|
jqElement.addClass('command'); |
|
976
|
|
|
ko.bindingHandlers[jqElement.is('form') ? 'submit' : 'click'] |
|
977
|
|
|
.init.apply(oViewModel, Array.prototype.slice.call(arguments)); // eslint-disable-line prefer-rest-params |
|
978
|
|
|
}, |
|
979
|
|
|
|
|
980
|
|
|
update: function(oElement, fValueAccessor) { |
|
981
|
|
|
|
|
982
|
|
|
var |
|
983
|
|
|
bResult = true, |
|
|
|
|
|
|
984
|
|
|
jqElement = $(oElement), |
|
985
|
|
|
oCommand = fValueAccessor(); |
|
986
|
|
|
|
|
987
|
|
|
bResult = oCommand.enabled(); |
|
988
|
|
|
jqElement.toggleClass('command-not-enabled', !bResult); |
|
989
|
|
|
|
|
990
|
|
|
if (bResult) |
|
991
|
|
|
{ |
|
992
|
|
|
bResult = oCommand.canExecute(); |
|
993
|
|
|
jqElement.toggleClass('command-can-not-be-execute', !bResult); |
|
994
|
|
|
} |
|
995
|
|
|
|
|
996
|
|
|
jqElement.toggleClass('command-disabled disable disabled', !bResult).toggleClass('no-disabled', !!bResult); |
|
997
|
|
|
|
|
998
|
|
|
if (jqElement.is('input') || jqElement.is('button')) |
|
999
|
|
|
{ |
|
1000
|
|
|
jqElement.prop('disabled', !bResult); |
|
1001
|
|
|
} |
|
1002
|
|
|
} |
|
1003
|
|
|
}; |
|
1004
|
|
|
|
|
1005
|
|
|
// extenders |
|
1006
|
|
|
|
|
1007
|
|
|
ko.extenders.trimmer = function(oTarget) |
|
1008
|
|
|
{ |
|
1009
|
|
|
var |
|
1010
|
|
|
Utils = require('Common/Utils'), |
|
1011
|
|
|
oResult = ko.computed({ |
|
1012
|
|
|
'read': oTarget, |
|
1013
|
|
|
'write': function(sNewValue) { |
|
1014
|
|
|
oTarget(Utils.trim(sNewValue.toString())); |
|
1015
|
|
|
}, |
|
1016
|
|
|
'owner': this |
|
1017
|
|
|
}); |
|
1018
|
|
|
|
|
1019
|
|
|
oResult(oTarget()); |
|
1020
|
|
|
return oResult; |
|
1021
|
|
|
}; |
|
1022
|
|
|
|
|
1023
|
|
|
ko.extenders.posInterer = function(oTarget, iDefault) |
|
1024
|
|
|
{ |
|
1025
|
|
|
var |
|
1026
|
|
|
Utils = require('Common/Utils'), |
|
1027
|
|
|
oResult = ko.computed({ |
|
1028
|
|
|
'read': oTarget, |
|
1029
|
|
|
'write': function(sNewValue) { |
|
1030
|
|
|
var iNew = Utils.pInt(sNewValue.toString(), iDefault); |
|
1031
|
|
|
if (0 >= iNew) |
|
1032
|
|
|
{ |
|
1033
|
|
|
iNew = iDefault; |
|
1034
|
|
|
} |
|
1035
|
|
|
|
|
1036
|
|
|
if (iNew === oTarget() && '' + iNew !== '' + sNewValue) |
|
1037
|
|
|
{ |
|
1038
|
|
|
oTarget(iNew + 1); |
|
1039
|
|
|
} |
|
1040
|
|
|
|
|
1041
|
|
|
oTarget(iNew); |
|
1042
|
|
|
} |
|
1043
|
|
|
}); |
|
1044
|
|
|
|
|
1045
|
|
|
oResult(oTarget()); |
|
1046
|
|
|
return oResult; |
|
1047
|
|
|
}; |
|
1048
|
|
|
|
|
1049
|
|
|
ko.extenders.limitedList = function(oTarget, mList) |
|
1050
|
|
|
{ |
|
1051
|
|
|
var |
|
1052
|
|
|
Utils = require('Common/Utils'), |
|
1053
|
|
|
oResult = ko.computed({ |
|
1054
|
|
|
'read': oTarget, |
|
1055
|
|
|
'write': function(sNewValue) { |
|
1056
|
|
|
|
|
1057
|
|
|
var |
|
1058
|
|
|
sCurrentValue = ko.unwrap(oTarget), |
|
1059
|
|
|
aList = ko.unwrap(mList); |
|
1060
|
|
|
|
|
1061
|
|
|
if (Utils.isNonEmptyArray(aList)) |
|
1062
|
|
|
{ |
|
1063
|
|
|
if (-1 < Utils.inArray(sNewValue, aList)) |
|
1064
|
|
|
{ |
|
1065
|
|
|
oTarget(sNewValue); |
|
1066
|
|
|
} |
|
1067
|
|
|
else if (-1 < Utils.inArray(sCurrentValue, aList)) |
|
1068
|
|
|
{ |
|
1069
|
|
|
oTarget(sCurrentValue + ' '); |
|
1070
|
|
|
oTarget(sCurrentValue); |
|
1071
|
|
|
} |
|
1072
|
|
|
else |
|
1073
|
|
|
{ |
|
1074
|
|
|
oTarget(aList[0] + ' '); |
|
1075
|
|
|
oTarget(aList[0]); |
|
1076
|
|
|
} |
|
1077
|
|
|
} |
|
1078
|
|
|
else |
|
1079
|
|
|
{ |
|
1080
|
|
|
oTarget(''); |
|
1081
|
|
|
} |
|
1082
|
|
|
} |
|
1083
|
|
|
}).extend({'notify': 'always'}); |
|
1084
|
|
|
|
|
1085
|
|
|
oResult(oTarget()); |
|
1086
|
|
|
|
|
1087
|
|
|
if (!oResult.valueHasMutated) |
|
1088
|
|
|
{ |
|
1089
|
|
|
oResult.valueHasMutated = function() { |
|
1090
|
|
|
oTarget.valueHasMutated(); |
|
1091
|
|
|
}; |
|
1092
|
|
|
} |
|
1093
|
|
|
|
|
1094
|
|
|
return oResult; |
|
1095
|
|
|
}; |
|
1096
|
|
|
|
|
1097
|
|
|
ko.extenders.reversible = function(oTarget) |
|
1098
|
|
|
{ |
|
1099
|
|
|
var mValue = oTarget(); |
|
1100
|
|
|
|
|
1101
|
|
|
oTarget.commit = function() |
|
1102
|
|
|
{ |
|
1103
|
|
|
mValue = oTarget(); |
|
1104
|
|
|
}; |
|
1105
|
|
|
|
|
1106
|
|
|
oTarget.reverse = function() |
|
1107
|
|
|
{ |
|
1108
|
|
|
oTarget(mValue); |
|
1109
|
|
|
}; |
|
1110
|
|
|
|
|
1111
|
|
|
oTarget.commitedValue = function() |
|
1112
|
|
|
{ |
|
1113
|
|
|
return mValue; |
|
1114
|
|
|
}; |
|
1115
|
|
|
|
|
1116
|
|
|
return oTarget; |
|
1117
|
|
|
}; |
|
1118
|
|
|
|
|
1119
|
|
|
ko.extenders.toggleSubscribe = function(oTarget, oOptions) |
|
1120
|
|
|
{ |
|
1121
|
|
|
oTarget.subscribe(oOptions[1], oOptions[0], 'beforeChange'); |
|
1122
|
|
|
oTarget.subscribe(oOptions[2], oOptions[0]); |
|
1123
|
|
|
|
|
1124
|
|
|
return oTarget; |
|
1125
|
|
|
}; |
|
1126
|
|
|
|
|
1127
|
|
|
ko.extenders.toggleSubscribeProperty = function(oTarget, oOptions) |
|
1128
|
|
|
{ |
|
1129
|
|
|
var sProp = oOptions[1]; |
|
1130
|
|
|
|
|
1131
|
|
|
if (sProp) |
|
1132
|
|
|
{ |
|
1133
|
|
|
oTarget.subscribe(function(oPrev) { |
|
1134
|
|
|
if (oPrev && oPrev[sProp]) |
|
1135
|
|
|
{ |
|
1136
|
|
|
oPrev[sProp](false); |
|
1137
|
|
|
} |
|
1138
|
|
|
}, oOptions[0], 'beforeChange'); |
|
1139
|
|
|
|
|
1140
|
|
|
oTarget.subscribe(function(oNext) { |
|
1141
|
|
|
if (oNext && oNext[sProp]) |
|
1142
|
|
|
{ |
|
1143
|
|
|
oNext[sProp](true); |
|
1144
|
|
|
} |
|
1145
|
|
|
}, oOptions[0]); |
|
1146
|
|
|
} |
|
1147
|
|
|
|
|
1148
|
|
|
return oTarget; |
|
1149
|
|
|
}; |
|
1150
|
|
|
|
|
1151
|
|
|
ko.extenders.falseTimeout = function(oTarget, iOption) |
|
1152
|
|
|
{ |
|
1153
|
|
|
oTarget.iFalseTimeoutTimeout = 0; |
|
1154
|
|
|
oTarget.subscribe(function(bValue) { |
|
1155
|
|
|
if (bValue) |
|
1156
|
|
|
{ |
|
1157
|
|
|
window.clearTimeout(oTarget.iFalseTimeoutTimeout); |
|
1158
|
|
|
oTarget.iFalseTimeoutTimeout = window.setTimeout(function() { |
|
1159
|
|
|
oTarget(false); |
|
1160
|
|
|
oTarget.iFalseTimeoutTimeout = 0; |
|
1161
|
|
|
}, require('Common/Utils').pInt(iOption)); |
|
1162
|
|
|
} |
|
1163
|
|
|
}); |
|
1164
|
|
|
|
|
1165
|
|
|
return oTarget; |
|
1166
|
|
|
}; |
|
1167
|
|
|
|
|
1168
|
|
|
ko.extenders.specialThrottle = function(oTarget, iOption) |
|
1169
|
|
|
{ |
|
1170
|
|
|
oTarget.iSpecialThrottleTimeoutValue = require('Common/Utils').pInt(iOption); |
|
1171
|
|
|
if (0 < oTarget.iSpecialThrottleTimeoutValue) |
|
1172
|
|
|
{ |
|
1173
|
|
|
oTarget.iSpecialThrottleTimeout = 0; |
|
1174
|
|
|
oTarget.valueForRead = ko.observable(!!oTarget()).extend({'throttle': 10}); |
|
1175
|
|
|
|
|
1176
|
|
|
return ko.computed({ |
|
1177
|
|
|
'read': oTarget.valueForRead, |
|
1178
|
|
|
'write': function(bValue) { |
|
1179
|
|
|
|
|
1180
|
|
|
if (bValue) |
|
1181
|
|
|
{ |
|
1182
|
|
|
oTarget.valueForRead(bValue); |
|
1183
|
|
|
} |
|
1184
|
|
|
else |
|
1185
|
|
|
{ |
|
1186
|
|
|
if (oTarget.valueForRead()) |
|
1187
|
|
|
{ |
|
1188
|
|
|
window.clearTimeout(oTarget.iSpecialThrottleTimeout); |
|
1189
|
|
|
oTarget.iSpecialThrottleTimeout = window.setTimeout(function() { |
|
1190
|
|
|
oTarget.valueForRead(false); |
|
1191
|
|
|
oTarget.iSpecialThrottleTimeout = 0; |
|
1192
|
|
|
}, oTarget.iSpecialThrottleTimeoutValue); |
|
1193
|
|
|
} |
|
1194
|
|
|
else |
|
1195
|
|
|
{ |
|
1196
|
|
|
oTarget.valueForRead(bValue); |
|
1197
|
|
|
} |
|
1198
|
|
|
} |
|
1199
|
|
|
} |
|
1200
|
|
|
}); |
|
1201
|
|
|
} |
|
1202
|
|
|
|
|
1203
|
|
|
return oTarget; |
|
1204
|
|
|
}; |
|
1205
|
|
|
|
|
1206
|
|
|
ko.extenders.idleTrigger = function(oTarget) |
|
1207
|
|
|
{ |
|
1208
|
|
|
var Enums = require('Common/Enums'); |
|
1209
|
|
|
oTarget.trigger = ko.observable(Enums.SaveSettingsStep.Idle); |
|
1210
|
|
|
return oTarget; |
|
1211
|
|
|
}; |
|
1212
|
|
|
|
|
1213
|
|
|
// functions |
|
1214
|
|
|
|
|
1215
|
|
|
ko.observable.fn.idleTrigger = function() |
|
1216
|
|
|
{ |
|
1217
|
|
|
return this.extend({'idleTrigger': true}); |
|
1218
|
|
|
}; |
|
1219
|
|
|
|
|
1220
|
|
|
ko.observable.fn.validateNone = function() |
|
1221
|
|
|
{ |
|
1222
|
|
|
this.hasError = ko.observable(false); |
|
1223
|
|
|
return this; |
|
1224
|
|
|
}; |
|
1225
|
|
|
|
|
1226
|
|
|
ko.observable.fn.validateEmail = function() |
|
1227
|
|
|
{ |
|
1228
|
|
|
var Utils = require('Common/Utils'); |
|
1229
|
|
|
|
|
1230
|
|
|
this.hasError = ko.observable(false); |
|
1231
|
|
|
|
|
1232
|
|
|
this.subscribe(function(sValue) { |
|
1233
|
|
|
sValue = Utils.trim(sValue); |
|
1234
|
|
|
this.hasError('' !== sValue && !(/^[^@\s]+@[^@\s]+$/.test(sValue))); |
|
1235
|
|
|
}, this); |
|
1236
|
|
|
|
|
1237
|
|
|
this.valueHasMutated(); |
|
1238
|
|
|
return this; |
|
1239
|
|
|
}; |
|
1240
|
|
|
|
|
1241
|
|
|
ko.observable.fn.validateSimpleEmail = function() |
|
1242
|
|
|
{ |
|
1243
|
|
|
var Utils = require('Common/Utils'); |
|
1244
|
|
|
|
|
1245
|
|
|
this.hasError = ko.observable(false); |
|
1246
|
|
|
|
|
1247
|
|
|
this.subscribe(function(sValue) { |
|
1248
|
|
|
sValue = Utils.trim(sValue); |
|
1249
|
|
|
this.hasError('' !== sValue && !(/^.+@.+$/.test(sValue))); |
|
1250
|
|
|
}, this); |
|
1251
|
|
|
|
|
1252
|
|
|
this.valueHasMutated(); |
|
1253
|
|
|
return this; |
|
1254
|
|
|
}; |
|
1255
|
|
|
|
|
1256
|
|
|
ko.observable.fn.deleteAccessHelper = function() |
|
1257
|
|
|
{ |
|
1258
|
|
|
this.extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [null, |
|
1259
|
|
|
function(oPrev) { |
|
1260
|
|
|
if (oPrev && oPrev.deleteAccess) |
|
1261
|
|
|
{ |
|
1262
|
|
|
oPrev.deleteAccess(false); |
|
1263
|
|
|
} |
|
1264
|
|
|
}, function(oNext) { |
|
1265
|
|
|
if (oNext && oNext.deleteAccess) |
|
1266
|
|
|
{ |
|
1267
|
|
|
oNext.deleteAccess(true); |
|
1268
|
|
|
} |
|
1269
|
|
|
} |
|
1270
|
|
|
]}); |
|
1271
|
|
|
|
|
1272
|
|
|
return this; |
|
1273
|
|
|
}; |
|
1274
|
|
|
|
|
1275
|
|
|
ko.observable.fn.validateFunc = function(fFunc) |
|
1276
|
|
|
{ |
|
1277
|
|
|
var Utils = require('Common/Utils'); |
|
1278
|
|
|
|
|
1279
|
|
|
this.hasFuncError = ko.observable(false); |
|
1280
|
|
|
|
|
1281
|
|
|
if (Utils.isFunc(fFunc)) |
|
1282
|
|
|
{ |
|
1283
|
|
|
this.subscribe(function(sValue) { |
|
1284
|
|
|
this.hasFuncError(!fFunc(sValue)); |
|
1285
|
|
|
}, this); |
|
1286
|
|
|
|
|
1287
|
|
|
this.valueHasMutated(); |
|
1288
|
|
|
} |
|
1289
|
|
|
|
|
1290
|
|
|
return this; |
|
1291
|
|
|
}; |
|
1292
|
|
|
|
|
1293
|
|
|
module.exports = ko; |
|
1294
|
|
|
|